from django.contrib import admin

from nutrition.models import FoodDescription, FoodGroup, NutrientData
from nutrition.models import NutrientDefinition, SourceCode, DataDerivation
from nutrition.models import Weight, Footnote, DataSourceLink, DataSource

class FoodDescriptionAdmin(admin.ModelAdmin):
    raw_id_fields = ('food_group', 'nutrient_data', 'weight', 'footnote')
    search_fields = ('long_desc', 'shrt_desc', 'comname', 'manufacname', 'ref_desc', 'sciname')
    ordering = ('long_desc', )

class FoodGroupAdmin(admin.ModelAdmin):
    list_display = ('fdgrp_cd', 'fdgrp_desc')
    ordering = ('fdgrp_cd', )
    search_fields = ('fdgrp_desc', )

class NutrientDataAdmin(admin.ModelAdmin):
    list_display = ('__unicode__', 'nutr_no', 'data_derivation', 'num_studies', 'num_data_pts', 'std_error')
    list_filter = ('data_derivation', )
    ordering = ('ndb_no', )
    raw_id_fields = ('nutrient_def', 'source_code', 'data_derivation', 'data_source_ln')

class NutrientDefinitionAdmin(admin.ModelAdmin):
    list_display = ('sr_order', '__unicode__', 'units')
    list_filter = ('units', )
    ordering = ('sr_order', )
    search_fields = ('tagname', 'tagnames')

class SourceAdmin(admin.ModelAdmin):
    search_fields = ('srccd_desc', )

class DataDerivationAdmin(admin.ModelAdmin):
    list_display = ('deriv_cd', 'deriv_desc')
    ordering = ('deriv_cd', )
    search_fields = ('deriv_desc', )



class DataSourceAdmin(admin.ModelAdmin):
    list_display = ('authors', 'title', 'year')
    ordering = ('authors', 'title', 'year')
    search_fields = ('authors', 'title', 'year', 'journal', 'vol_city')

admin.site.register(FoodDescription, FoodDescriptionAdmin)
admin.site.register(FoodGroup, FoodGroupAdmin)
admin.site.register(NutrientData, NutrientDataAdmin)
admin.site.register(NutrientDefinition, NutrientDefinitionAdmin)
admin.site.register(SourceCode, SourceAdmin)
admin.site.register(DataDerivation, DataDerivationAdmin)
admin.site.register(Weight)
admin.site.register(Footnote)
admin.site.register(DataSourceLink)
admin.site.register(DataSource, DataSourceAdmin)